package p1;

import org.junit.Test;

import java.util.HashMap;

public class LeetcodeTest_3 {

    /**
     * 无重复字符的最长子串
     * 给定一个字符串 s ，请你找出其中不含有重复字符的 最长子串 的长度。
     * 输入: s = "abcabcbb"
     * 输出: 3
     * 解释: 因为无重复字符的最长子串是 "abc"，所以其长度为 3。
     */
    @Test
    public void t1(){
        String s = "abcabcbb";
        int count = lengthOfLongestSubstring(s);
        System.out.println(count);
    }

    public int lengthOfLongestSubstring(String s) {
        HashMap<String, Integer> map = new HashMap<>();
        char[] charArray = s.toCharArray();
        int startIndex = 0;
        int endIndex = 0;
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];


            char start = charArray[startIndex];
            char end = charArray[endIndex];
            String str = getStr(start, end, charArray);
            if (start != end && !str.contains(String.valueOf(c)) && !map.containsKey(str)){
                map.put(str,str.length());
            }
            if (start == end && !map.containsKey(str)){
                map.put(str,str.length());
            }


        }


        return 0;
    }

    private String getStr(int left,int right,char[] charArray){
        if (left == right){
            return String.valueOf(charArray[left]);
        }
        String str = "";
        for (int i = left; i <= right; i++) {
            str += charArray[i];
        }
        return str;
    }

}
